﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SVC.client;

namespace UI.Forms
{
    public partial class ProductINData : FormBase1
    {
        public ProductINData()
        {
            InitializeComponent();
        }

        private void bind()
        {
            var list = my.bw.ProductIN_M_Get("", my.ACID);
            gridControl1.DataSource = list;

            dateEdit1.EditValue = DateTime.Now;

            BindingList<View_Client_lite> clients = my.bw.View_Client_lite_List(true, my.ACID);

            //经销商
            lue_Client.Properties.DataSource = clients;
            lue_Client.EditValue = null;

            rue_Client.DataSource = clients;
            rue_Client.DisplayMember = "ClientName";
            rue_Client.ValueMember = "ClientID";
        }

        private void ProductINData_Load(object sender, EventArgs e)
        {
            bind();
        }

        #region GridView
        private void gridView1_MouseDown(object sender, MouseEventArgs e)
        {
            
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hInfo = gridView1.CalcHitInfo(new Point(e.X,e.Y));
            if (e.Button == MouseButtons.Left && e.Clicks == 2)
            {
                ProductIN_M m = gridView1.GetRow(gridView1.FocusedRowHandle) as ProductIN_M;
                if (m != null)
                {
                    
                    var pro = gridView1.GetRow(gridView1.FocusedRowHandle) as ProductIN_M;
                    ProductINStore store = new ProductINStore();
                    store.MdiParent = my.mainform;
                    if (store.IsDisposed)
                    {
                        store.Close();
                    }
                    store.Billno = m.billid;
                    store.Show();
                }
            }
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (true)
            {

            }
            if (e.FocusedRowHandle >= 0)
            {
                ProductIN_M m = gridView1.GetRow(e.FocusedRowHandle) as ProductIN_M;
                //if (!string.IsNullOrWhiteSpace(d.phone))
                //{
                //btn_WH.Enabled = true;
                //}
            }
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            ProductIN_M m = gridView1.GetRow(e.RowHandle) as ProductIN_M;
            

        }

        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {

        }
        #endregion

        /// <summary>
        /// 修改入库信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnUp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var pro = gridView1.GetRow(gridView1.FocusedRowHandle) as ProductIN_M;
            ProductINStore store = new ProductINStore();
            store.MdiParent = my.mainform;
            store.Billno = pro != null ? pro.billid : "";
            store.Show();
        }
        /// <summary>
        /// 新增入库单信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var pro = gridView1.GetRow(gridView1.FocusedRowHandle) as ProductIN_M;
            ProductINStore store = new ProductINStore();
            store.MdiParent = my.mainform;
            store.Billno = "";
            store.Show();
        }
    }
}
